package com.conan.dailyflickr.provider;

import java.util.HashMap;
import java.util.Map;

import android.content.Context;

public class DailyFlickrModel extends AbsPrefModel{
	private static String tag = "DailyFlickrModel";
	
	// provide a unique name to store date
	private static String DAILY_FLICKR_WIDGET_RPOVIDER_NAME = "com.handroid.dailyflickr.dailyFclikrProvider";
	
	// variables to paint the widget view
	private String mPage = "1";
	private static String F_PAGE = "page";
	
	private String mPages = "1";
	private static String F_PAGES = "pages";
	
	private String mCurrPage = "1";
	private static String F_CURR_PAGE = "cur_page";
	
	// contructor/gets/sets
	public DailyFlickrModel(int intanceId){
		super(intanceId);
	}
	
	public DailyFlickrModel(int instanceId, String page, String pages, String currPage ) {
		super(instanceId);
		mPage = page;
		mPages = pages;
		mCurrPage = currPage;
	}
	
	public void setPage(String page){ mPage = page; }
	public void setPages(String pages){ mPages = pages; }
	public void setCurrPage(String currPage){ mCurrPage = currPage; }
	
	// implemented abstract methods
	@Override
	public void setValueForPref(String key, String value) {
		if(key.equals(getStoredKeyForFieldName(F_PAGE))){
			this.mPage = value;
			return;
		}
		if(key.equals(getStoredKeyForFieldName(F_PAGES))){
			this.mPages = value;
			return;
		}
		if(key.equals(getStoredKeyForFieldName(F_CURR_PAGE))){
			this.mCurrPage = value;
			return;
		}
	}
	@Override
	public String getPrefName() {
		return DAILY_FLICKR_WIDGET_RPOVIDER_NAME;
	}

	@Override
	public Map<String, String> getPrefsToSave() {
		Map map = new HashMap();
		map.put(F_PAGE, this.mPage);
		map.put(F_PAGES, this.mPages);
		map.put(F_CURR_PAGE, this.mCurrPage);
		return map;
	}
	
	public String toString(){
		StringBuffer sbuff = new StringBuffer();
		sbuff.append("id: " + mId);
		sbuff.append("page: " + mPage);
		sbuff.append("pages: " + mPages);
		sbuff.append("curr_page: " + mCurrPage);	
		
		return sbuff.toString();
	}
	
	public static void clearAllPreferences(Context ctx){
		AbsPrefModel.clearAllPreferences(ctx, DAILY_FLICKR_WIDGET_RPOVIDER_NAME);
	}
	
	public static DailyFlickrModel retrieveModel(Context ctx, int widgetId){
		DailyFlickrModel model = new DailyFlickrModel(widgetId);
		boolean found = model.retievePrefs(ctx);
		return found ? model : null;
	}
	
	@Override	
	public void init() {
		// TODO Auto-generated method stub		
	}
	
}
